#include <cstdio>
#include <vector>
#include <cstring>

using namespace std;

struct Node
{
    int v, w;
    Node( ) { }
    Node( int _v, int _w )
        : v( _v ), w( _w ) { }
};

int mmin( int a, int b ) { return ( a < b )?a :b; }

int n, m;
vector<Node> li[ 1001 ];
bool visit[ 1001 ];

void init( )
{
    int i, u, v, w;
    for ( i = 0; i < n; i++ )
        li[ i ].clear( );
    for ( i = 0; i < n - 1; i++ )
    {
        scanf("%d%d%d", &u, &v, &w); u--; v--;
        li[ u ].push_back( Node( v, w ) );
        li[ v ].push_back( Node( u, w ) );
    }
}

int dfs( int p, int q )
{
    int i, ret = 0;
    bool flag = false;
    for ( i = 0; i < li[ p ].size( ); i++ )
    {
        if ( !visit[ li[ p ][ i ].v ] )
        {
            visit[ li[ p ][ i ].v ] = true;
            flag = true;
            if ( li[ p ][ i ].w <= q )
                ret += mmin( dfs( li[ p ][ i ].v, q ), li[ p ][ i ].w );
            else
                ret += dfs( li[ p ][ i ].v, q );
        }
    }
    if ( !flag )
        return 1000000;
    return ret;
}

void work( )
{
    int left = 0, right = 1000, mid;
    while ( left < right )
    {
        mid = ( left + right ) / 2;
        memset( visit, 0, sizeof( visit ) );
        visit[ 0 ] = true;
        if ( dfs( 0, mid ) > m )
            left = mid + 1;
        else
            right = mid;
    }
    memset( visit, 0, sizeof( visit ) );
    visit[ 0 ] = true;
    if ( dfs( 0, 1000 ) > m )
        puts("-1");
    else
        printf("%d\n", left);
}

int main( )
{
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        if ( n == 0 && m == 0 )
            break;
        if ( n <= 1 )
        {
            puts("0");
            continue;
        }
        init( );
        work( );
//        visit[ 0 ] = true;
//        printf("%d\n", dfs( 0, 6 ));
    }
    return 0;
}
